package cn.kgc.controller;

import cn.kgc.service.TestService;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author YC
 */
@RestController
@RequestMapping("/sentinel")
@Api(tags = "sentinel流控规则")
public class SentinelController {

    @GetMapping("/method1")
    @SentinelResource(value = "m1", blockHandlerClass = SentinelBlockHandler.class, blockHandler = "method1blockHandler")
    public String method1() {
        return "method1";
    }

    @GetMapping("/method2")
    @SentinelResource(value = "m2", blockHandlerClass = SentinelBlockHandler.class, blockHandler = "method1blockHandler")
    public String method2() {
        return "method2";
    }

    @Resource
    private TestService testService;

    @GetMapping("/test1")
    public String test1() {
        return testService.common();
    }

    @GetMapping("/test2")
    public String test2() {
        return testService.common();
    }

}
